/**
 * 作者: hxl
 * 日期: 2025-02-11 18:00:08
 * 备注: 限时活动表
 */
package com.motu.monstercity.server.game.commondata.act;

import com.motu.monstercity.server.game.base.AllParam;
import com.motu.monstercity.server.game.logic.RankActManager;
import com.motu.vertx.module.utility.toolset.TimeUtils;
import com.motu.vertx.module.utility.toolset.Tool;
import io.vertx.core.json.JsonObject;

import java.util.List;

public class ActConfig extends ActConfigModel {
    public static final int GROUP_ID_LOCAL = 1; // 本服活动
    public static final int GROUP_ID_GLOBAL = 2; // 跨服活动

    private int[] timeTaskArray = null;
    private int[] rechargeArray = null;
    private int[] rechargeTaskArray = null;
    private int[] shopIdArray = null;

    public ActConfig(JsonObject obj) {
        super(obj);
        timeTaskArray = Tool.isEmpty(timeTask) ? new int[0] : Tool.strToIntArray(timeTask, ";");
        rechargeArray = Tool.isEmpty(recharge) ? new int[0] : Tool.strToIntArray(recharge, ";");
        rechargeTaskArray = Tool.isEmpty(rechargeTask) ? new int[0] : Tool.strToIntArray(rechargeTask, ";");
        shopIdArray = Tool.isEmpty(shopId) ? new int[0] : Tool.strToIntArray(shopId, ";");
    }

    /***
     * 获取活动的开始时间和结束时间
     * @param actStartTime 活动流初始时间
     * @return
     */
    public long[] getConfigTime(int actGroup, long actStartTime, long curTime){
        long startTime = TimeUtils.getStartTimeOfDay(actStartTime+(this.getStartDay()-1) * TimeUtils.DAY);//取开始日期0点的时间戳
        long endTime = startTime+(this.getEndDay()-this.getStartDay()+1) * TimeUtils.DAY - 2 * TimeUtils.HOUR;//取结束日期23:59:59点的时间戳
        long closeTime = endTime + TimeUtils.DAY;

//		System.out.println("*** startTime:"+TimeUtils.getTimeFullStr(startTime) +"  endTime:"+TimeUtils.getTimeFullStr((endTime)));
//		int curTime = Tool.getCurTime();
        int days = TimeUtils.getDiffDay(curTime, actStartTime)+1;//天数距离从第一天开始
        int allDays = RankActManager.getActDays(groupId);
        if(days > allDays && groupId == ActConfig.GROUP_ID_GLOBAL) {//超过天数，开始循环了
            int cycleNum = (days -this.getStartDay())/allDays;//经过了几次循环
            int time1 = cycleNum*allDays*Tool.DAY;//补上时间差
            startTime += time1;
            endTime += time1;
            closeTime += time1;
        }
        return new long[]{startTime,endTime, closeTime};
    }

    /***
     * 判断是否在冲榜活动的领奖时间
     * @param actGroup
     * @param actStartTime
     * @param curTime
     * @return
     */
    public boolean isInGetRewardTime(int actGroup,long actStartTime,long curTime) {
        long times[] = getConfigTime(actGroup,actStartTime,curTime);
//		int startTime = times[0];
        long endTime = times[1];
        return curTime > endTime && curTime <= endTime+ AllParam.RANK_ACT_REWARD_END_HOUR*Tool.HOUR;
    }
    /***
     * 获取活动流开始日期的字符串，如20180208
     * @param startTime
     * @return
     */
    public String getConfigDateStr(long startTime) {
        return TimeUtils.getDayStr(startTime);
    }

    /***
     * 根据排行类型获取活动对象
     * @param rankType 排行类型
     * @return 活动对象
     */
    public ActTopRanking getActTopRankingByType(byte rankType) {
        List<ActTopRanking> actTopRankingList = RankActManager.getActTopRankingList(rankList);
        for (ActTopRanking act : actTopRankingList) {
            if(act != null && act.getType() == rankType) {
                return act;
            }
        }
        return null;
    }

    public int[] getTimeTaskArray() {
        return timeTaskArray;
    }
    public int[] getRechargeArray() {
        return rechargeArray;
    }
    public int[] getRechargeTaskArray() {
        return rechargeTaskArray;
    }

    public int[] getShopIdArray() {
        return shopIdArray;
    }
}
